package com.ssm.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.demo.model.User;
import com.ssm.demo.service.UserService;


@Controller
@RequestMapping(value = "/user")
public class UserController {

	@Autowired
	public UserService userService;
	
	/**
	 * 添加一条完整记录
	 * @param record
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/insertRecord")
	public int insertRecord(User record){
		return userService.insertRecord(record);
	}

	/**
	 * 添加指定列的数据
	 * @param record
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/insertSelective")
	public int insertSelective(User record){
		return userService.insertSelective(record);
	}

	/**
	 * 通过Id(主键)删除一条记录
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/deleteById")
	public int deleteById(Integer id){
		return userService.deleteById(id);
	}

	/**
	 * 按Id(主键)修改指定列的值
	 * @param record
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/updateByIdSelective")
	public int updateByIdSelective(User record){
		return userService.updateByIdSelective(record);
	}

	/**
	 * 按Id(主键)修改指定列的值
	 * @param record
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/updateById")
	public int updateById(User record){
		return userService.updateById(record);
	}

	/**
	 * 计算表中的总记录数
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/countRecord")
	public int countRecord(){
		return userService.countRecord();
	}

	/**
	 * 根据条件计算记录条数
	 * @param record
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/countSelective")
	public int countSelective(User record){
		return userService.countSelective(record);
	}

	/**
	 * 获得表中的最大Id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/maxId")
	public int maxId(){
		return userService.maxId();
	}

	/**
	 * 通过Id(主键)查询一条记录
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectById")
	public	User	selectById(Integer	id){
		User user = userService.selectById(id);
		return user;
	}

	/**
	 * 查询所有记录
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getAll")
	public List selectAll(){
		return userService.selectAll();
	}
}
